/*
  This file is part of 'Trivial chess'.

  'Trivial chess' is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  'Trivial chess' is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with 'Trivial chess'.  If not, see <http://www.gnu.org/licenses/>.
*/

/* SVN FILE: $Id$ */
/**
 * @author         $Author$
 * @version        $Rev$
 * @lastrevision   $Date$
 * @filesource     $URL$
 */

#ifndef COLORORD_H_
#define COLORORD_H_

#include <boost/cstdint.hpp>

#include "ColorAbstract.h"

template<typename Int = uint8_t>
class ColorOrd : public ColorAbstract<ColorOrd, Int> {
public:
	static const ColorOrd<Int> WHITE() { return ColorOrd<Int>(0); }
	static const ColorOrd<Int> BLACK() { return ColorOrd<Int>(1); }
	static const ColorOrd<Int> NIL()   { return ColorOrd<Int>(2); }
	static const ColorOrd<Int> END()   { return ColorOrd<Int>::NIL(); }
	static const ColorOrd<Int> REND()  { return ColorOrd<Int>(-1); }
public:
	ColorOrd<Int>() {}

	explicit ColorOrd<Int>(const Int color) : color(color)  {}
	explicit ColorOrd<Int>(const std::string str)  { this->me().fromStr(str); }

	Int toInt() const {
		return this->color;
	}

	void fromInt(const Int color) {
		this->color = color;
	}

	ColorOrd<Int> operator++() {
		return ColorOrd(++this->color);
	}

	ColorOrd<Int> operator--() {
		return ColorOrd(--this->color);
	}

	bool operator==(const ColorOrd<Int> color) const {
		return this->color == color.color;
	}

	void setRival() {
		this->color ^= 1;
	}
private:
	Int color;
};

#endif /* COLORORD_H_ */
